/*
 * Copyright© 2003-2019 浙江汇信科技有限公司, All Rights Reserved.
 */
package com.icinfo.cloud.provider.punish.config.controller;

import com.google.common.annotations.VisibleForTesting;
import com.icinfo.cloud.common.core.page.PageResponse;
import com.icinfo.cloud.provider.punish.config.dto.*;
import com.icinfo.cloud.provider.punish.config.service.IConfigRegisterCaseService;
import com.icinfo.framework.common.web.Result;
import com.icinfo.framework.core.web.BaseController;
import com.icinfo.framework.tools.utils.StringUtils;
import org.apache.xmlbeans.impl.xb.xsdschema.Public;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.executable.ValidateOnExecution;
import java.util.List;

/**
 * 描述:  config_register_case 对应的Controller类.<br>
 *
 * @author framework generator
 * @date 2022年11月30日
 */
@RestController
@RequestMapping("/punish/ucase/registerCaseConfig")
public class ConfigRegisterCaseController extends BaseController {
    /**
     * 日志记录器
     */
    private static final Logger logger = LoggerFactory.getLogger(ConfigRegisterCaseController.class);

    @Autowired
    private IConfigRegisterCaseService configRegisterCaseService;

    /**
     * 新增配置项
     * @param request
     * @return
     */
    @PostMapping("/addConfig")
    public Result<String> addConfig(@RequestBody @Validated ConfigRegisterCaseAddRequest request){
        int i = configRegisterCaseService.addConfig(request);
        if (i > 0){
            return Result.success("添加成功");
        }else {
            return Result.error("添加失败");
        }
    }

    /**
     * 增加材料配置
     * @param request
     * @return
     */
    @PostMapping("/addMaterial")
    public Result<String> addMaterial(@RequestBody @Validated ConfigRegisterCaseAddMaterialRequest request){
        int i = configRegisterCaseService.addMaterial(request);
        if (i > 0){
            return Result.success("添加成功");
        }else {
            return Result.error("添加失败");
        }
    }

    /**
     * 配置项状态修改 是否启用；1启用 0未启用
     * @param request
     * @return
     */
    @PostMapping("/editState")
    public Result<String> editState(@RequestBody @Validated ConfigRegisterCaseEditStateRequest request){
        int i = configRegisterCaseService.editState(request);
        if (i > 0){
            return Result.success("状态修改成功");
        }else {
            return Result.error("状态修改失败");
        }
    }

    /**
     * 配置列表分页查询
     * @param request
     * @return
     */
    @PostMapping("/page")
    public Result<PageResponse> page(@RequestBody @Validated ConfigRegisterCasePageRequest request){
        List<ConfigRegisterCasePageResponse> list = configRegisterCaseService.pageList(request);
        return Result.success(new PageResponse<>(list));
    }
}
